<template>
  <!--ASN/收货单-->
  <div id="Asndetails">
    <v-table
      :pageSize="pageSize"
      :page="page"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @setdialog="setdialog"
      @upData="getTableData"
      ref="table"
    ></v-table>

    <el-dialog
      :title="$t('in.condition')"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      width="30%"
    >
      <el-row>
        <el-col :span="6" style="height:40px;line-height: 40px">
          LPN:
        </el-col>
        <el-col :span="18">
          <el-input v-model="newlpn" placeholder=""></el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6" style="height:40px;line-height: 40px">
          收料数量:
        </el-col>
        <el-col :span="18">
          <el-input v-model="newrtxqty" placeholder=""></el-input>
        </el-col>
      </el-row>

      <span slot="footer">
        <el-button type="primary" @click="defineClick"
          >{{$t('common.confirm')}}</el-button
        >
        <el-button @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import details from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

import table from "commons/Table";

export default {
  mixins: [baseMixin],
  props: {
    inputData: {
      type: Object,
    },
  },
  name: "asnDetails",
  data() {
    return {
      dialogVisible: false,
      newlpn: "",
      newrtxqty: "",
      rules: {},
      loading: false,
      tableConfig: [
        {
          label: this.$t("outbound.userlinenumber"),
          prop: "lineno",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.receiptkey2"),
          prop: "receiptkey",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stylekey"),
          prop: "style",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("config.shipper"),
          prop: "storerkey",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffName"),
          prop: "descr",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffCode"),
          prop: "sku",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.suppliername1"),
          prop: "suppliername",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffType"),
          prop: "rtxwlsx",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffUom"),
          prop: "uom",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffSpec"),
          prop: "rtxspec",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffColor"),
          prop: "color",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffPrice"),
          prop: "rtxprice",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffQty1"),
          prop: "qty1",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffQty2"),
          prop: "rtxqty",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffQty3"),
          prop: "rtx_firstok",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.stuffQty4"),
          prop: "qty2",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.rtxqcqty"),
          prop: "rtxqcqty",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.rtxokqty"),
          prop: "rtxokqty",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.rtxngqty"),
          prop: "rtxngqty",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.rtxrate"),
          prop: "rtxrate",
          input: "input",
          disabled: false,
        },
        {
          label: this.$t("in.rtxsampqty"),
          prop: "rtxsampqty",
          input: "input",
          disabled: false,
        },
      ],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
    };
  },
  computed: {},
  methods: {
    //确定打印条码的数量
    defineClick() {
      if (this.newlpn == null || this.newlpn == "") {
        this.$message.error(this.$tj('in.lpn','app.emptyMes'));
        this.newlpn = null;
        return;
      }
      let reg = /^\+?[1-9]\d*$/; //大于零的正整数
      if (!reg.test(this.newrtxqty)) {
        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'));
        this.newrtxqty = null;
        return;
      }
      let params = [];
      if (this.tableSelectData.length === 1) {
        params.push(this.tableSelectData[0]);
      } else {
        this.$message.error(this.$t('msg.msg56'));
        return;
      }
      this.$api
        .post(`/cfLpn/` + this.newlpn + "/" + this.newrtxqty, params)
        .then((res) => {
            this.$message.success(this.$t('app.saveMes'));
            this.dialogVisible = false;
        });
    },
    //进入详情
    async setdialog(data) {
      this.$parent.setdialog(data, "1");
    },
    //选中的内容
    selectData(data) {
      this.tableSelectData = data;
    },
    inintDialog() {
      this.dialogVisible = true;
    },
    //搜索的值
    searhData(data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    async getTableData(page, data) {
      try {
        this.loading = true;
        let id = this.inputData.selectData.rtxchecklist;
        let res = await this.$api.post(
          `/queryRtxQcDetailList/` + id + `/${page}`,
          data
        );
          this.loading = false;
          this.tableData = res.page.list;
          this.page = res.page.curPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
      } catch (e) {
        this.loading = false;
        this.$message.error(e);
      }
    },
  },
  mounted() {
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData(data) {
      if (data.length >= 2) {
        this.$message.error(this.$t('msg.msg32'));
      }
      if (data.length === 1) {
        this.$parent.change(false);
      } else {
        this.$parent.change(true);
      }
    },
  },
  components: {
    "v-table": table,
  },
};
</script>

<style scoped></style>
